package com.imooc.ad.utils;

import com.imooc.ad.exception.AdException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.time.DateUtils;


import java.util.Date;

/*
 * @author Qihs
 */
public class CommonUtils {

    //定义日期字符串的格式
    private static String[] parsePatterns = {
      "yyyy-mm-dd", "yyyy/mm/mm","yyyy.mm.dd"
    };
    //获取一个字符串的MD5
    public static String md5(String value){
        return DigestUtils.md5Hex(value).toUpperCase();
    }

    /**
     * 实现字符串转换成Date的方法工具类
     * */
    public static Date parseStringData(String dataString) throws AdException{
        try {
            return DateUtils.parseDate(dataString, parsePatterns);
        } catch (Exception ex){
            throw  new AdException(ex.getMessage());
        }
    }


}
